package com.lc.afbx.adapters;

import android.content.Context;
import android.net.Uri;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiWeiQuanZiXun;
import com.lc.afbx.util.TimeUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/6/3.
 */
public class WeiQuanAdapter extends BaseAdapter {
    private List<GetApiWeiQuanZiXun.Data> dataList;
    private LayoutInflater inflater;
    private Context context;

    public WeiQuanAdapter(Context context, List<GetApiWeiQuanZiXun.Data> dataList) {
        inflater = LayoutInflater.from(context);
        this.dataList = dataList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_weiquanzixun, null);
            BaseApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);

            convertView.setBackgroundColor(context.getResources().getColor(R.color.white));

            holder = new ViewHolder();

            holder.answer = (TextView) convertView.findViewById(R.id.answer_weiquan);
            holder.question = (TextView) convertView.findViewById(R.id.question_content_weiquan);
            holder.name = (TextView) convertView.findViewById(R.id.name_weiquan);
            holder.time = (TextView) convertView.findViewById(R.id.time_weiquan);
            holder.isReplay = (TextView) convertView.findViewById(R.id.isReplay);
            holder.touXiang = (SimpleDraweeView) convertView.findViewById(R.id.touxiang_weiquan);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.time.setText(TimeUtil.times(dataList.get(position).posttime));
        holder.name.setText(dataList.get(position).username);
        holder.question.setText(dataList.get(position).title);

        holder.touXiang.setImageURI(Uri.parse(dataList.get(position).picurl));

        if ("1".equals(dataList.get(position).restate)) {
            holder.isReplay.setText("回复：");
            holder.isReplay.setTextColor(context.getResources().getColor(R.color.textcolorHei));
            holder.answer.setText(Html.fromHtml(dataList.get(position).reply));
        } else {
            holder.isReplay.setText("等待回复");
            holder.isReplay.setTextColor(context.getResources().getColor(R.color.titleColor));
            holder.answer.setText(null);
        }

        return convertView;
    }

    class ViewHolder {
        SimpleDraweeView touXiang;
        TextView name, time, question, answer, isReplay;
    }
}
